<template>
	<view>
	
		<view class="header">
			<view class="title">欢迎来到工作台</view>
		</view>
		
		<view class="container">
			
			<!-- 搜索区域 -->
			<view class="data-section">
				<!-- <view class="section-title">时间段查询</view> -->
				<view>
					<view class="search-wrapper">
						<view class="search-column">
							<view class="search-item">
								<picker mode="date" :value="startDate" @change="onStartDateChange">
									<view class="picker">{{startDate || '请选择开始时间'}}</view>
								</picker>
							</view>
							<view class="search-item">
								<picker mode="date" :value="endDate" @change="onEndDateChange">
									<view class="picker">{{endDate || '请选择结束时间'}}</view>
								</picker>
							</view>
						</view>
						<button class="search-btn" @click="searchData">查询</button>
					</view>
				</view>
			</view>

			<!-- 数据统计区域 -->
			<view class="data-section">
				<view class="section-title">数据统计</view>
				<view class="data-grid">
					<view class="data-item">
						<view class="value">{{eventData.data_statistics.visit_users}}</view>
						<view class="label">访问用户</view>
					</view>
					<view class="data-item">
						<view class="value">{{eventData.data_statistics.invite_views}}</view>
						<view class="label">邀请浏览</view>
					</view>
					<view class="data-item">
						<view class="value">{{eventData.data_statistics.share_count}}</view>
						<view class="label">分享数量</view>
					</view>
					<view class="stats-item">
						<view class="value">{{eventData.data_statistics.staff_count}}</view>
						<view class="label">员工数量</view>
					</view>
				</view>

				<view class="stats-grid">
					<view class="stats-item">
						<view class="value">{{eventData.data_statistics.online_count}}</view>
						<view class="label">线上单</view>
					</view>
					<view class="data-item">
						<view class="value">{{eventData.data_statistics.offline_count}}</view>
						<view class="label">线下单</view>
					</view>
					<view class="data-item">
						<view class="value">{{eventData.data_statistics.paid_users}}</view>
						<view class="label">支付用户</view>
					</view>
					<view class="data-item">
						<view class="value"></view>
						<view class="label"></view>
					</view>
				</view>
			</view>
			
			<!-- 金额统计区域 -->
			<view class="data-section">
				<view class="section-title">金额统计</view>
				<view class="data-grid">
					<view class="data-item">
						<view class="value">{{eventData.financial_statistics.received_amount}}</view>
						<view class="label">收款金额</view>
					</view>
					<view class="data-item">
						<view class="value">{{eventData.financial_statistics.reward_amount}}</view>
						<view class="label">奖励金额</view>
					</view>
					<view class="data-item">
						<view class="value">{{eventData.financial_statistics.refund_amount}}</view>
						<view class="label">退款金额</view>
					</view>
					<view class="data-item">
						<view class="value">{{eventData.financial_statistics.account_balance}}</view>
						<view class="label">账户余额</view>
					</view>
				</view>
			</view>
			
			<!-- 新老客统计区域 -->
			<view class="data-section">
				<view class="section-title">新老客统计</view>
				<view class="data-grid">
					<view class="data-item">
						<view class="value">{{eventData.customer_statistics.new_customer_count}}</view>
						<view class="label">新客数</view>
					</view>
					<view class="data-item">
						<view class="value">{{eventData.customer_statistics.old_customer_count}}</view>
						<view class="label">老客数</view>
					</view>
					<view class="data-item">
						<view class="value"></view>
						<view class="label"></view>
					</view>
					<view class="data-item">
						<view class="value"></view>
						<view class="label"></view>
					</view>
				</view>
			</view>

			<!-- 活动管理区域 -->
			<view class="management-section" style="margin-bottom: 60rpx;">
				<view class="section-title">活动管理</view>
				<view class="grid-container">
					<navigator :url="'/pages/activity/index?activityId=' + activityId" class="grid-item">
						<image src="/static/work/icon-url.png" mode="aspectFit" class="grid-icon"></image>
						<text class="grid-text">进入链接</text>
					</navigator>
					<navigator url="/pages/staff/staffStats" class="grid-item">
						<image src="/static/work/icon-rank.png" mode="aspectFit" class="grid-icon"></image>
						<text class="grid-text">员工统计</text>
					</navigator>
					<navigator url="/pages/staff/intention" class="grid-item">
						<image src="/static/work/icon-user.png" mode="aspectFit" class="grid-icon"></image>
						<text class="grid-text">意向客户</text>
					</navigator>
					<navigator url="/pages/staff/refundOrder" class="grid-item">
						<image src="/static/work/icon-refunds.png" mode="aspectFit" class="grid-icon"></image>
						<text class="grid-text">退款订单</text>
					</navigator>
					<navigator url="/pages/staff/manualOrder" class="grid-item">
						<image src="/static/work/icon-log.png" mode="aspectFit" class="grid-icon"></image>
						<text class="grid-text">手动录单</text>
					</navigator>
					<navigator url="/pages/staff/screen" class="grid-item">
						<image src="/static/work/icon-screen.png" mode="aspectFit" class="grid-icon"></image>
						<text class="grid-text">电脑投屏</text>
					</navigator>
					<navigator url="/pages/staff/exportOrder" class="grid-item">
						<image src="/static/work/icon-excel.png" mode="aspectFit" class="grid-icon"></image>
						<text class="grid-text">导出订单</text>
					</navigator>
					<navigator url="/pages/staff/visitorList" class="grid-item">
						<image src="/static/work/icon-short-url.png" mode="aspectFit" class="grid-icon"></image>
						<text class="grid-text">链接访客</text>
					</navigator>
					<navigator url="/pages/staff/ranking" class="grid-item">
						<image src="/static/work/icon-user-rank.png" mode="aspectFit" class="grid-icon"></image>
						<text class="grid-text">推荐排行</text>
					</navigator>
					<navigator url="/pages/staff/redPacketRecord" class="grid-item">
						<image src="/static/work/icon-hbao.png" mode="aspectFit" class="grid-icon"></image>
						<text class="grid-text">红包记录</text>
					</navigator>
					<navigator url="/pages/staff/data" class="grid-item">
						<image src="/static/work/icon-data.png" mode="aspectFit" class="grid-icon"></image>
						<text class="grid-text">订单数据</text>
					</navigator>
					<navigator url="/pages/staff/clerkManage" class="grid-item">
						<image src="/static/work/icon-workers.png" mode="aspectFit" class="grid-icon"></image>
						<text class="grid-text">店员管理</text>
					</navigator>
					<navigator url="/pages/staff/sourceClerk" class="grid-item">
						<image src="/static/work/icon-fenzu.png" mode="aspectFit" class="grid-icon"></image>
						<text class="grid-text">店员溯源</text>
					</navigator>
					<navigator url="/pages/staff/confirmPrizeList" class="grid-item">
						<image src="/static/work/icon-order.png" mode="aspectFit" class="grid-icon"></image>
						<text class="grid-text">核销记录</text>
					</navigator>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import * as api from '@/api/staff'
	import * as userApi from '@/api/user'
	import storage from '@/utils/storage'
	export default {
		components: {},
		data() {
			return {
				startDate: '',
				endDate: '',
				activityId: 0,
				eventData: [],
			}
		},
		onLoad() {
			var that = this;
			this.activityId = storage.get('activityId');
			api.eventOverview({
				activity_id: this.activityId,
				start_time: this.startDate,
				end_time: this.endDate
			}).then(res => {
				that.eventData = res.data;
			});
			userApi.dashboard({
				activityId: storage.get('activityId')
			}).then(res => {
				if (res.data.role != 1) {
					uni.redirectTo({
						url: '/pages/user/center/index?activityId=' + storage.get('activityId')
					})
				}
			});
		},
		methods: {
			onStartDateChange(e) {
				this.startDate = e.detail.value
			},
			onEndDateChange(e) {
				this.endDate = e.detail.value
			},
			/**
			 * 根据时间查询数据
			 */
			searchData() {
				api.eventOverview({
					activity_id: this.activityId,
					start_time: this.startDate,
					end_time: this.endDate
				}).then(res => {
					that.eventData = res.data;
				});
			}
		},
		mounted() {

		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F6F7FB;
	}
	
	.header {
		background-color: #FE963F;
		position: inherit;
		width: 100%;
		height: 250rpx;
		border-radius: 0rpx 0rpx 20rpx 20rpx;
	}
	
	.header > .title {
		color: #fff;
		padding: 30rpx;
		font-size: 40rpx;
		font-weight: bold;
	}

	.container {
		position: absolute;
		left: 0;
		right: 0;
		top: 100rpx;
	}

	.data-section, .management-section {
		margin: 20rpx 30rpx;
		background-color: #fff;
		border-radius: 16rpx;
		padding: 30rpx;

		.section-title {
			text-align: center;
			font-size: 32rpx;
			margin-bottom: 30rpx;
			position: relative;

			&::before,
			&::after {
				content: "—";
				margin: 0 20rpx;
				color: #999;
			}
		}
	}

	.data-grid,
	.stats-grid {
		display: flex;
		justify-content: space-between;
		margin-bottom: 30rpx;

		.data-item,
		.stats-item {
			flex: 1;
			text-align: center;

			.value {
				font-size: 28rpx;
				font-weight: bold;
				margin-bottom: 10rpx;
			}

			.label {
				font-size: 24rpx;
				color: #666;
			}
		}

		.red .value {
			color: #ff0000;
		}

		.purple .value {
			color: #800080;
		}

		.green .value {
			color: #008000;
		}
	}

	.grid-container {
		display: grid;
		grid-template-columns: repeat(5, 1fr);
		gap: 30rpx;

		.grid-item {
			display: flex;
			flex-direction: column;
			align-items: center;

			.grid-icon {
				width: 80rpx;
				height: 80rpx;
				margin-bottom: 10rpx;
			}

			.grid-text {
				font-size: 24rpx;
				color: #333;
			}
		}
	}

	.tab-bar {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		height: 100rpx;
		background-color: #fff;
		display: flex;
		justify-content: space-around;
		align-items: center;
		border-top: 1rpx solid #eee;

		.tab-item {
			display: flex;
			flex-direction: column;
			align-items: center;

			.tab-icon {
				width: 48rpx;
				height: 48rpx;
				margin-bottom: 4rpx;
			}

			.tab-text {
				font-size: 24rpx;
				color: #666;
			}
		}
	}
	
	.search-wrapper {
		display: flex;
		align-items: stretch;
	}
	
	.search-column {
		flex: 1;
		margin-right: 20rpx;
	}
	
	.search-item {
		margin-bottom: 20rpx;
		
		&:last-child {
			margin-bottom: 0;
		}
		
		.picker {
			height: 88rpx;
			line-height: 88rpx;
			background-color: #f5f5f5;
			border-radius: 8rpx;
			padding: 0 30rpx;
			font-size: 28rpx;
			color: #333;
		}
	}
	
	.search-btn {
		width: 120rpx;
		background-color: #FE963F;
		color: #fff;
		font-size: 32rpx;
		border-radius: 8rpx;
		border: none;
		flex-shrink: 0;
		display: flex;
		align-items: center;
		justify-content: center;
		
		&:active {
			opacity: 0.8;
		}
	}
</style>